<?php

namespace App\Http\Controllers\Open;

use Illuminate\Support\Facades\Request as RequestFacade;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;
use ZBrettonYe\Geetest\Geetest;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;

class LocationController extends Controller
{
    /**
     * 获取客户端传递的位置参数.
     */

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(\Illuminate\Http\Request $request)
    {
        $validator = [
            'client_id'=>'required|string|exists:gpsadv_users,user_client_id',
            "lotitude"=> "required|string",
            "latitude"=> "required|string"
        ];

        return Validator::make($request->all(), $validator, [
            'client_id.required' => trans('The client_id is required'),
            'lotitude.required' => trans('The lotitude is required'),
            'latitude.required' => trans('The latitude is required'),
            "client_id.exists"=>trans("The client_id is not exists")
        ]);
    }
    //后续再增加一个中间件的检测，当注册成功后，会返回一个token，后续登录还需要带上token
    public function sendPos(\Illuminate\Http\Request $request)
    {

        $validator = $this->validator($request);

        if ($validator->fails()) {
            $error_msg = $validator->errors()->first();
            return Response::returns([
                'errors' => 1,
                'message' => $error_msg
            ], 422);
        }
        $data = $request->all();
        dump($data);
    }
}
